package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumInfoIndexVo;
import com.atguigu.tingshu.vo.search.AlbumItemVo;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import com.atguigu.tingshu.vo.search.AlbumSearchVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;




    @GetMapping("channel/{category1Id}")
    public Result<List<Map<String, Object>>> channel(@PathVariable("category1Id")Long category1Id) throws IOException {
        List<Map<String, Object>> map =   this.searchService.channel(category1Id);
      return Result.ok(map);
    }

    @PostMapping
    public  Result<AlbumSearchResponseVo> searchAlbumInfo(@RequestBody AlbumIndexQuery albumIndexQuery){
        AlbumSearchResponseVo albumSearchResponseVo = this.searchService.searchAlbumInfo(albumIndexQuery);
        return Result.ok(albumSearchResponseVo);
    }

    @GetMapping("completeSuggest/{keyword}")
    private Result<List<String>> completeSuggest(@PathVariable String keyword){
        List<String> list =  this.searchService.completeSuggest(keyword);
        return Result.ok(list);
    }

    @GetMapping("findRankingList/{category1Id}/{statType}")
    public Result<List<AlbumInfoIndexVo>> findRankingList(@PathVariable Long category1Id, @PathVariable String statType){
        List<AlbumInfoIndexVo> albumInfoIndexVos =  this.searchService.findRankingList(category1Id,statType);
        return Result.ok(albumInfoIndexVos);
    }

    @PostMapping("syncDataToEs")
    public Result syncDataToEs(){
        this.searchService.syncDataToEs();
        return Result.ok();
    }

}

